home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / ana11 / convert.c < prev    next >
C/C++ Source or Header  |  1993-01-15  |  2KB  |  67 lines

  1. /*
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     *********************************************************************
  13.  */
  14.  
  15. #include "ana.h"
  16.  
  17. private    char    result[ 200 ];
  18. private    char    HexMap[] = "0123456789abcdefX";
  19.  
  20.  
  21. /*
  22.  * Convert a trace entry (vector) to an ascii string
  23.  */
  24. public char *HistToStr( hist, nbits, b_digit, offset )
  25.   hptr  *hist;
  26.   int   nbits, b_digit, offset;
  27.   {
  28.     register char  *p; 
  29.     register int   i, j, digit;
  30.  
  31.     p = result;
  32.     j = nbits % b_digit;
  33.     if( j == 0 )
  34.     j = b_digit;
  35.     for( i = nbits; i > 0; i -= j )
  36.       {
  37.     digit = 0;
  38.     do
  39.       {
  40.         switch( (*hist)->val )
  41.           {
  42.         case LOW :
  43.             digit = (digit << 1);
  44.             break;
  45.         case HIGH :
  46.             digit = (digit << 1) | 1;
  47.             break;
  48.         case X :
  49.             digit = 16;
  50.             while( j != 1 )
  51.               {
  52.             j--;
  53.             hist += offset;
  54.               }
  55.             break;
  56.           }
  57.         j--;
  58.         hist += offset;
  59.       }
  60.     while( j > 0 );
  61.     *p++ = HexMap[ digit ];
  62.     j = b_digit;
  63.       }
  64.     *p = '\0';
  65.     return( result );
  66.   }
  67.